package com.hundun.hddeal.controller;

import com.hundun.hddeal.entity.QinIuBean;
import com.hundun.hddeal.response.Result;
import com.hundun.hddeal.response.ResultUtil;
import com.hundun.hddeal.util.QiniuUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;


@Slf4j
@RestController
@RequestMapping("/upload")
public class UpLoadingController {

    /**
     * 上传
     */
    @PostMapping("image")
    @ResponseBody
    Result uploadChatImage(@RequestParam("file") MultipartFile file) {
        log.info(""+file+"");
        if(file.isEmpty()) {
            return ResultUtil.error("文件为空");
        }
        try {
            QinIuBean qinIuBean = new QiniuUtil().upload(file.getBytes(), System.currentTimeMillis() + file.getOriginalFilename());

            return ResultUtil.success(100,"上传成功",QiniuUtil.QINNIU_URL + qinIuBean.key);
        } catch (IOException e) {
            e.printStackTrace();
            return ResultUtil.error();
        }
    }


}
